package spindles.gwt.server.util;

import java.io.IOException;

import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

import org.apache.commons.io.FileUtils;

import spindles.api.util.ApplicationException;
import spindles.gwt.server.ServletUtil;

public class SessionListener implements HttpSessionListener {

	public void sessionCreated(HttpSessionEvent se) {		
		ServletUtil.getSessionExpDir(se).mkdir();		
	}

	public void sessionDestroyed(HttpSessionEvent se) {
		try {
			FileUtils.forceDelete(ServletUtil.getSessionExpDir(se));
			se.getSession().invalidate();
		} catch (IOException e) {
			throw new ApplicationException(e);
		}	
	}	

}
